const jwt = require('jsonwebtoken');
//签名值
let secret = 'indesic'; //签名值

module.exports = {

    //签名
    async sign(param, next) {
        let cb = false;
        try {
            let tokenSign = await jwt.sign(param, secret);
            if (tokenSign) {
                cb = tokenSign;
            };
        } catch (e) {
            cb = false;
        } finally {
            return cb;
        }
    },

    //验签
    async verify(param, next) {
        let cb = false;
        try {
            let tokenVer = await jwt.verify(String(param), secret);
            let tokenId = tokenVer.id;
            if (tokenVer) {
                cb = tokenVer;
            };
        } catch (e) {
            cb = false;
        } finally {
            return cb;
        }
    },

};